/*
 * @lc app=leetcode.cn id=面试题 17.06 lang=cpp
 * @lcpr version=30204
 *
 * [面试题 17.06] 2出现的次数
 */

// @lcpr-template-start
using namespace std;
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// @lcpr-template-end
// @lc code=start
class Solution
{
public:
    int numberOf2sInRange(int n)
    {
        if (n < 1)
            return 0;
        int count = 0;
        long base = 1;
        int round = n;
        while (round > 0)
        {
            int cur = round % 10;
            round /= 10;
            count += round * base;
            if (cur == 2)
                count += (n % base) + 1;
            else if (cur < 2)
                ;
            else 
                count += base;
            base *= 10;
        }
        return count;
    }
};
// @lc code=end

/*
// @lcpr case=start
// 25\n
// @lcpr case=end

 */
